﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ConnectSQLServer.Common;

namespace ConnectSQLServer.Controls
{
    public partial class DatabaseExplorer : UserControl
    {
        public TreeView treeViewDB;
        public DatabaseExplorer()
        {
            InitializeComponent();
            treeViewDB = tvDatabaseExplorer;
        }
        
        private void DatabaseExplorer_Load(object sender, EventArgs e)
        {
        }

        private void Refresh_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                GlobalVariable.DBExplorerManager.RefreshTreeView();
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("Error " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            this.Cursor = Cursors.Default;
        }

        private void Connect_Click(object sender, EventArgs e)
        {
            AddConnection frmAddConnection = new AddConnection();
            frmAddConnection.ShowDialog();
        }

        private void Disconnect_Click(object sender, EventArgs e)
        {

        }

        #region Event Hanlde ContextMenuStrip Databases
        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Refresh_Click(sender, e);
        }

        private void addNewConnectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Connect_Click(sender, e);
        }

        private void disconectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Disconnect_Click(sender, e);
        }
        #endregion

        
    }
}
